<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::CoreExtensions::Integer::Time</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::CoreExtensions::Integer::Time</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activesupport/lib/active_support/core_ext/integer/time_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Enables the use of time calculations and declarations, like 45.minutes +
2.hours + 4.years.
</p>
<p>
These methods use Time#advance for precise date calculations when using
from_now, ago, etc. as well as adding or subtracting their results from a
<a href="Time.html">Time</a> object. For example:
</p>
<pre>
  # equivalent to Time.now.advance(:months =&gt; 1)
  1.month.from_now

  # equivalent to Time.now.advance(:years =&gt; 2)
  2.years.from_now

  # equivalent to Time.now.advance(:months =&gt; 4, :years =&gt; 5)
  (4.months + 5.years).from_now
</pre>
<p>
While these methods provide precise calculation when used as in the
examples above, care should be taken to note that this is not true if the
result of `<a href="Time.html#M000466">months</a>&#8217;, `<a
href="Time.html#M000468">years</a>&#8217;, etc is converted before use:
</p>
<pre>
  # equivalent to 30.days.to_i.from_now
  1.month.to_i.from_now

  # equivalent to 365.25.days.to_f.from_now
  1.year.to_f.from_now
</pre>
<p>
In such cases, Ruby&#8216;s core <a
href="http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html">Date</a>
and <a
href="http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html">Time</a>
should be used for precision date and time arithmetic
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000467">month</a>&nbsp;&nbsp;
      <a href="#M000466">months</a>&nbsp;&nbsp;
      <a href="#M000469">year</a>&nbsp;&nbsp;
      <a href="#M000468">years</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000467" class="method-detail">
        <a name="M000467"></a>

        <div class="method-heading">
          <span class="method-name">month</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Time.html#M000466">months</a>
</p>
        </div>
      </div>

      <div id="method-M000466" class="method-detail">
        <a name="M000466"></a>

        <div class="method-heading">
          <a href="#M000466" class="method-signature">
          <span class="method-name">months</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000466-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000466-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb, line 33</span>
33:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">months</span>
34:           <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span> <span class="ruby-operator">*</span> <span class="ruby-value">30</span>.<span class="ruby-identifier">days</span>, [[<span class="ruby-identifier">:months</span>, <span class="ruby-keyword kw">self</span>]])
35:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000469" class="method-detail">
        <a name="M000469"></a>

        <div class="method-heading">
          <span class="method-name">year</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Time.html#M000468">years</a>
</p>
        </div>
      </div>

      <div id="method-M000468" class="method-detail">
        <a name="M000468"></a>

        <div class="method-heading">
          <a href="#M000468" class="method-signature">
          <span class="method-name">years</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000468-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000468-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb, line 38</span>
38:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">years</span>
39:           <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span> <span class="ruby-operator">*</span> <span class="ruby-value">365.25</span>.<span class="ruby-identifier">days</span>, [[<span class="ruby-identifier">:years</span>, <span class="ruby-keyword kw">self</span>]])
40:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>